#include "logineventwindow.h"
#include "ui_logineventwindow.h"
#include <QDebug>
LoginEventWindow::LoginEventWindow(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::LoginEventWindow)
{
    ui->setupUi(this);
    userEdit = new CustomEidt(QIcon("://img/account.png"),this);
    pwdEdit = new CustomEidt(QIcon("://img/闭眼睛.png"),this);

    connect(pwdEdit->act,&QAction::triggered,[=](){
        if(pwdEdit->echoMode() == QLineEdit::Normal)
        {
            pwdEdit ->setEchoMode(QLineEdit::Password);
            pwdEdit->setActionIcon(QIcon("://img/眼睛.png"));
        }else{
            pwdEdit ->setEchoMode(QLineEdit::Normal);
            pwdEdit->setActionIcon(QIcon("://img/闭眼睛.png"));
        }
    });
    pwdEdit->move(0,50);

    userEdit->installEventFilter(this);
    pwdEdit->installEventFilter(this);
}

LoginEventWindow::~LoginEventWindow()
{
    delete ui;
}

void LoginEventWindow::keyPressEvent(QKeyEvent *e)
{
    Q_UNUSED(e)

//    close();
}

bool LoginEventWindow::eventFilter(QObject *watched, QEvent *event)
{
    if(userEdit == watched)
    {
        if(event->type() == QEvent::KeyPress)
        {
            qDebug()<<"LoginEventWindow::eventFilter";
            if(static_cast<QKeyEvent*>(event)->key() == Qt::Key_Return)
            {
                pwdEdit->setFocus();
                return true;
            }
        }
    }
    if(pwdEdit == watched)
    {
        if(event->type() == QEvent::KeyPress)
        {
            if(static_cast<QKeyEvent*>(event)->key() == Qt::Key_Return)
            {
                AboutDialog *bDlg = new AboutDialog;
                bDlg->setAttribute(Qt::WA_DeleteOnClose);
                bDlg->show();
                this->close();
                return true;
            }
        }
    }
    return QWidget::eventFilter(watched,event);
}

